import { createApp, h } from 'vue';
import duiModal from './Modal.vue';
export const openModal = (options: any) => {
  const {
    title,
    content,
    confirm,
    cancel,
    backdropClose,
  } = options;
  
  const div = document.createElement('div');
  document.body.appendChild(div);

  const modal = createApp({
    render() {
      return h(duiModal, {
        visible: true,
        confirm,
        cancel,
        backdropClose,
        'onUpdate:visible'(visible: boolean) {
          if (!visible) {
            // 销毁
            modal.unmount(div);
            div.remove();
          }
        }
      }, {
        // 第二个参数放置插槽
        title,
        content,
      });
    }
  });

  modal.mount(div);
}
